{template '_header'}

<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}设备{if !empty($item['id'])}({$item['name']}){/if}</span>
</div>

<div class="page-content">
    <div class="page-sub-toolbar">
        <span class=''>
		    {ifp 'sgoods.add'}
			    <a class="btn btn-primary btn-sm" href="{php echo webUrl('sgoods/post')}">添加新设备</a>
            {/if}
            <a class="btn btn-default  btn-sm" href="{php echo webUrl('sgoods/index')}">返回列表</a>
        </span>
    </div>

<form id="setform"  class="form-horizontal form-validate" onsubmit="return check();" {ifp 'sgoods.edit'}action="" method="post"{/if}>

<input type="hidden" name="id" value="{$item['id']}" />

<div class="tabs-container">
    <ul class="nav nav-tabs" id="myTab">
        <li  {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}class="active"{/if}><a href="#tab_basic">基本信息</a></li>
        <li  {if $_GPC['tab']=='more'}class="active"{/if}><a href="#tab_more">更多信息</a></li>
        <li  {if $_GPC['tab']=='status'}class="active"{/if}><a href="#tab_status">状态设置</a></li>
    </ul>
    <div class="tab-content ">
        <div class="tab-pane {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}active{/if}" id="tab_basic">{template 'sgoods/post/basic'}</div>
        <div class="tab-pane {if $_GPC['tab']=='more'}active{/if}" id="tab_more">{template 'sgoods/post/more'}</div>
        <div class="tab-pane {if $_GPC['tab']=='status'}active{/if}" id="tab_status">{template 'sgoods/post/status'}</div>
    </div>
</div>

{ifp 'sgoods.edit'}
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <input type="submit"  value="提交" class="btn btn-primary" />
    </div>
</div>
{/if}

</form>
</div>
<script language='javascript'>
    require(['bootstrap'], function () {
        $('#myTab a').click(function (e) {
            $('#tab').val($(this).attr('href'));
            e.preventDefault();
            $(this).tab('show');
        })
    });

    function check() {
        var p='';
        $('.ow_name').each(function () {
            var temp_price_name=$(this).val();
            if(temp_price_name)
            {
                var temp_price_set=$(this).parent().parent().parent();
                var temp_price=$(temp_price_set).find('.ow_ratio').val();
                if(temp_price!=="")
                {
                    var temp_priceid=$(temp_price_set).data('priceid');
                    p=p+temp_priceid+".|."+temp_price_name+".|."+temp_price;
                    p=p+"^~^";
                }
            }
        });
        $('#price_price').val(p);
    }
    function new_price(){
        {php $item['id']=intval($item['id'])}
        $("#price").before('<div class="form-group" data-priceid=""> <label class="col-xs-12 col-sm-3 col-md-2 control-label">创业者</label> <div class="col-sm-7 col-xs-12"> <div class="input-group" > <div class="input-group-addon">名称</div> <input class="form-control ow_name" type="text" name="ow_name" /> <div class="input-group-addon">占有比例</div> <input class="form-control ow_ratio" type="text" name="ow_ratio" /> <div class="input-group-addon">%</div> <div class="input-group-addon" onclick="del_price(this)" data-id="'+{$item['id']}+'" style="background-color: #fb6b5b;color: #fff;font-weight: bold">删除</div></div></div></div>');
    }
    function del_price(obj) {
        var self=obj;
        $(self).parent().parent().parent().remove();
    }

</script>


{template '_footer'}